//
//  DestinationManager.m
//  We_Travel
//
//  Created by lanou3g on 15/12/22.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "DestinationManager.h"
#import "NH_DataDownloadTools.h"
#import "Destination.h"

@implementation DestinationManager
+ (instancetype)shareDestinationManager{
    static DestinationManager *destination = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        destination = [DestinationManager new];
    });
    return destination;
}
- (void)requireData:(NSString *)urlStr idlast:(NSInteger)idlast{
    [self.SelectedDesArray removeAllObjects];
    [self.destinationArray removeAllObjects];
    NSString *string =[NSString stringWithFormat:urlStr,idlast];
    [NH_DataDownloadTools downloadDataWithURL:string andMethod:@"get" andBody:nil andBlock:^(NSData *data) {
        NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        for (NSDictionary *dict in array) {
            Destination *destination = [Destination new];
            [destination setValuesForKeysWithDictionary:dict];
            [self.destinationArray addObject:destination];
        }
        if (self.resultBlock) {
            self.resultBlock();
        }
    }];
}
//懒加载
- (NSMutableArray *)destinationArray{
    if (!_destinationArray) {
        _destinationArray = [NSMutableArray array];
    }
    return _destinationArray;
}
- (NSMutableArray *)SelectedDesArray{
    if (!_SelectedDesArray) {
        _SelectedDesArray = [NSMutableArray array];
    }
    return _SelectedDesArray;
}
@end
